<?php
/**
 * @package   auto_occasion
 * @subpackage 
 * @author    CMS
 * @copyright  2011
 * @license    All rights reserved
 */

class versionSrv {

     /**
     * Fonction permettant de récupérer un essai à partir de l'id d'une gamme
     * @param int $IdGammeModele
     * @return object
     *
     */
    public function getByIdGammeModele ($IdGammeModele) {
        // instanciation de la factory
        $maFactory = jDao::get("commun~essai_version");
        

        return $maFactory->getByGammeModeleId($IdGammeModele)->fetchAll();
         

    }

     /**
     * Fonction permettant de sauvegarder les versions
     * @return object $version
     *
     */
    public function ajouter ($version) {
        // instanciation de la factory
        $maFactory = jDao::get("commun~essai_version");
        $records   = jDao::createRecord("commun~essai_version");

        $records->ess_gammeModele_id = $version->ess_gammeModele_id;
        $records->name               = $version->name;
        $records->content            = $version->content;
        $records->media              = $version->media;
        
        
        if ($maFactory->insert($records)) {
            return $records->version_id;
        }

    }
     /**
     * Fonction permettant de modifier les versions
     * @return object $partenaire
     *
     */
    public function modifier ($version) {
        // instanciation de la factory
        $maFactory = jDao::get("commun~essai_version");
        $records   = $maFactory->get($version->version_id);

        $records->ess_gammeModele_id = $version->ess_gammeModele_id;
        $records->name               = $version->name;
        $records->content            = $version->content;
        $records->media              = $version->media;
        

        if ($maFactory->update($records)) {
            return $version->version_id;
        }

    }

     /**
     * Fonction permettant de récupérer une version à partir de l'id d'un essai
     * @param int $essaiId
     * @return object
     *
     */
    public function getByEssaiId ($essaiId) {
        // instanciation de la factory
        $maFactory = jDao::get("commun~ao_essais_version");
        

        return $maFactory->getByEssaiId($essaiId)->fetchAll();
         

    }


}